<?php

/**
 * Flickr Photosets - Geotagged Photos Page
 * Displays the user's geotagged photos.
 * 
 * @author Brad Dougherty <bdougherty@gmail.com>
 * @version 2.0
 * @date 9/22/07
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License 3.0
 * @since File available since Release 1.0
 */

/*
Require the function library
This will include all other necessary files
*/
require_once 'lib.php';

/*
Initialize Flickr Photosets and Flickr
*/
$fp = new FlickrPhotosetsCanvas();

// If the user has disabled photosets
if (!$fp->config['enable_gallery_geotagged']) {
	$fp->error(FlickrPhotosetsErrors::$geotagged_disabled);
}

// To get photos with geo data, we have to authenticate
$fp->flickr->setToken($fp->config['flickr_token']);

// We will get only their public photos, unless they are set for private photos.
if ($fp->config['privacy_filter'] == $fp->privacy_filter['private']) {
	$photos = $fp->flickr->photos_getWithGeoData(array(
		'per_page'       => $fp->photos_per_page,
		'page'           => $fp->page,
		'extras'         => 'date_upload',
	));
}
else {
	$photos = $fp->flickr->photos_getWithGeoData(array(
		'privacy_filter' => $fp->privacy_filter['public'],
		'per_page'       => $fp->photos_per_page,
		'page'           => $fp->page,
		'extras'         => 'date_upload',
	));
}

// Get some counts
$photo_count = $photos['total'];
$page_count = $photos['pages'];

// Get the first and last photo
$first_photo = 1 + ($fp->photos_per_page * ($fp->page - 1));
$last_photo = $first_photo + ($fp->photos_per_page - 1);
$last_photo = ($last_photo > $photo_count) ? $photo_count : $last_photo;

?>

<fb:title><?=$fp->get_name(true)?> Geotagged Photos</fb:title>

<?=$fp->print_media_header()?>

<div style="margin-top:20px;"> </div>

<?=$fp->echo_tabs('geotagged')?>

<?php if ($photo_count < 1) {
	$fp->error(FlickrPhotosetsErrors::$no_geotagged_photos);
} else { ?>
	<div class="bar clearfix summary_bar">
		<div class="summary">
			<h4>
				Showing <?=$first_photo?> to <?=$last_photo?> of <?=$photo_count?> geotagged photos
				<span class="pipe">|</span>
				<a href="<?=$fp->flickr->urls_getUserPhotos($fp->nsid)?>map/">View Map on Flickr</a>
			</h4>
		</div>
		<?php $fp->pager($page_count); ?>
	</div>

	<div class="album">
		<table border="0" cellspacing="0">
			<tr>
				<?php
				$i = 0;
				foreach($photos['photo'] as $photo) {
					echo '<td><a href="'.$fp->app_url.'/photos/'.$fp->uid.'/'.$photo['id'].'/map/"><img src="'.$fp->flickr->buildPhotoUrl($photo, "thumbnail").'" alt="'.$photo['title'].'" title="'.$photo['title'].'" /></a></td>';
					$i++;
					if ($i > 4) {
						echo '</tr><tr>';
						$i = 0;
					}
				} ?>
			</tr>
		</table>	
	</div>
<?php } ?>

<div class="bar clearfix footer_bar">
	<?php $fp->pager($page_count); ?>
</div>

<?=$fp->echo_footer()?>